import { defineConfig, loadEnv } from 'vite'
import react from '@vitejs/plugin-react-swc'
import path from 'path'



// https://vitejs.dev/config/
export default ({ command, mode } : any) => {
  const env = loadEnv(mode, process.cwd()); // 在vite文件中获取环境变量，项目中其他地方是通过import.meta.env.VITE_ENV来使用的
  console.log('command', command);
  console.log('mode', mode);
  console.log('env', env);
  
  return defineConfig({
    plugins: [react()],
    // 配置项目别名
    resolve: {
      alias: {
        '@': path.resolve(__dirname, 'src'),
      },
    },
    server: {
      proxy: {
        '/v1_0': {
          target: 'http://geek.itheima.net',
          ws: true,
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/v1_0/, "/v1_0")
        },
        '/yhgl': {
          target: 'http://192.168.0.114:9081',
          ws: true,
          changeOrigin: true,
          rewrite: (path) => {
            return path.replace(/^\/yhgl/, "/yhgl")
          },
        },
      },
    },
  })
}
